
//
//  UIBarButtonItem+Extension.swift
//  CWWeibo06
//
//  Created by ycw on 2017/7/22.
//  Copyright © 2017年 xiaowei. All rights reserved.
//

import UIKit

/*
 1.在分类中无法定义指定构造函数
 */
extension UIBarButtonItem {
    
    //函数默认参数，如果有参数就进行传递，没有可以省略
    convenience init(title: String,imageNamed: String? = nil,target: Any?,action: Selector) {
        
        self.init()
        
        let button: UIButton = UIButton()
        
        if imageNamed != nil {
            button.setImage(UIImage(named: imageNamed!), for: .normal)
        }
        
        button.setTitle(title, for: .normal)
        
        button.setTitleColor(UIColor.darkGray, for: .normal)
        
        button.setTitleColor(UIColor.orange, for: .highlighted)
        
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        
        button.sizeToFit()
        
        button.addTarget(target, action: action, for: .touchUpInside)
        
        customView = button
        
    }
    
}





